package com.gaoshi.chapter4;

import java.io.IOException;
import java.io.PrintWriter;
import java.nio.charset.StandardCharsets;
import java.nio.file.Paths;
import java.util.Scanner;

public class StringTest {
    public static void main(String[] args) throws IOException {
//        String a = "Hello";
//        String b = "Hello";
//        System.out.println(a == b);
//
//        int[] codePoints = "郭".codePoints().toArray();
//        for (int i = 0; i < codePoints.length; i++) {
//            System.out.println(codePoints[i]);
//        }

//        Scanner in = new Scanner(System.in);
//        System.out.println("What is your name?");
//        String name = in.nextLine();
//
//        System.out.println("How old are you?");
//        int age = in.nextInt();
//
//        System.out.println("Hello, " + name + ". Next year , you'll be " + (++age));

//        for (int i = 0; i < 5; i++) {
//            System.out.println(in.nextInt());
//        }

//        Console cons = System.console();
//        String username = cons.readLine("User name: ");
//        char[] passwd = cons.readPassword("Password: ");

        double x = 10000.0 / 3.0;
        System.out.println(x);
        System.out.printf("%8.2f\n", x);
        System.out.printf("%+,.2f\n", -10000000.0 / 3.0);
        System.out.printf("%,(.2f\n", -10000000.0 / 3.0);

        // 读取文件
        int lines = 0;
        Scanner in = new Scanner(Paths.get("/Users/guoluyu/sdks/get-pip.py"), StandardCharsets.UTF_8);
        while (in.hasNext()) {
            lines++;
            in.nextLine();
        }
        System.out.println(lines);
        in.close();

        // 写入文件，会自动创建文件
        PrintWriter out = new PrintWriter("/Users/guoluyu/Documents/mytext.txt", StandardCharsets.UTF_8);
        out.println("不想出差！！！");
        out.printf("%.2s\n", 1000.0 / 3.0);
        out.flush();
        out.close();

        Scanner in1 = new Scanner("mytext.txt");
        while (in1.hasNext()) {
            System.out.println(in1.next());
        }
        in1.close();

        System.out.println(System.getProperty("user.dir"));
    }
}
